package com.example.demo.reference;

import java.util.LinkedHashMap;
import java.util.Map;

public class SimpleHashMapCache extends LinkedHashMap {

    private final int size;

    public SimpleHashMapCache(int size) {
        this.size = size;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry eldest) {
        return size() >= size;
    }

    public static void main(String[] args) {
        SimpleHashMapCache cache = new SimpleHashMapCache(3);
        for (int i = 0; i < 5; i++) {
            cache.put(i + "", i);
        }
        for (int i = 0; i < 5; i++) {
            System.out.println(cache.get(i + ""));
        }
    }

}
